'''
Created on 2013-6-27

@author: ZuoPeng
# '''
# 
# class P66(object):
#     '''
#     classdocs
#     '''
# 
# 
#     def __init__(self):
#         '''
#         Constructor
#         '''
# def p66(n):
# #Violence way, sadly i need a computer much faster to work this out.     
#     x = 1
#     x2_all = set()
#     D = set(range(1, n + 1))
#     while len(D) > 0:
#         print(str(len(D)) + ' ' + str(x))
#         x2 = x ** 2
#         if x2 < n + 1:D.remove(x2)
#         x2_all.add(x2)
#         for y2 in x2_all:
#             d = (x2 - 1) / y2
#             if int(d) == d and d in D:
#                 D.remove(d)
#         x += 1
#     return x - 1
import euler.fun
def p66(n):
    max_x = 0
    for x in range(2, n + 1):
        if x ** 0.5 > int(x ** 0.5):
            a = euler.fun.Pells_equation(x)[0]
            print(str(x) + ' ' + str(a))
            max_x = max(max_x, a)
    print(max_x)
p66(1000)




            
            
